import subprocess
import re
import sys
import time
import datetime

class Sensor:
	
	def __init__(self,N_sensor,N_pin):
		self.Senc = str(N_sensor).strip()
		self.Pin = str(N_pin).strip()
		#print self.Senc,self.Pin
	
	def Obtener_Datos(self):
		cadena = "sudo ./Adafruit_DHT "+str(self.Senc)+" "+str(self.Pin.strip())
		#print subprocess.check_output(["./Adafruit_DHT",str(11),str(4)])
		try:
			self.output = subprocess.check_output(["./Adafruit_DHT",self.Senc,self.Pin])
			#print "ACA"
			matches = re.search("Temp =\s+([0-9.]+)", self.output)
			temp = str(matches.group(1))
			
			matches = re.search("Hum =\s+([0-9.]+)", self.output)
			humidity = str(matches.group(1))
			
			return temp+"_"+humidity
		except:
			return "error"
